package com.sky.controller.user;


import com.sky.pojo.Category;
import com.sky.pojo.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;

import com.sky.service.admin.DishService;
import com.sky.service.admin.SetmealService;
import com.sky.service.user.UserOrderService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "C端口-菜品查询")
@RequestMapping("/user")
public class UserCategoryController {

    @Autowired
    private UserOrderService userOrderService;
    @Autowired
    private SetmealService setmealService;
    @Autowired
    private DishService dishService;

    /**
     * * CachePut：将方法返回值放入缓存，
     * value:缓存的名称，每个缓存名称下面可以有多个key，
     * key:缓存的key
     *
     * @return
     */
    @ApiOperation("查询分类")
    @GetMapping("/category/list")
    public Result<List<Category>> getCategory() {
        List<Category> categoryList = userOrderService.getCategory();
        return Result.success(categoryList);
    }

    @ApiOperation("根据分类id查询菜品")
    @GetMapping("/dish/list")
    public Result<List<DishVO>> get(Long categoryId) {

        List<DishVO> dishVOList = dishService.getDishCategoryId(categoryId);
        return Result.success(dishVOList);
    }

    @ApiOperation("根据分类id查询套餐")
    @GetMapping("/setmeal/list")
    public Result<List<Setmeal>> getSetmeal(Long categoryId) {
        List<Setmeal> setmealList = setmealService.getSetmeal(categoryId);
        return Result.success(setmealList);
    }

    /**
     * 套餐id查询包含的菜品
     *
     * @param setmealId
     * @return
     */
    @ApiOperation("套餐id查询包含的菜品列表")
    @GetMapping("/setmeal/dish/{setmealId}")
    public Result<List<DishItemVO>> getDish(@PathVariable Long setmealId) {
        List<DishItemVO> dishItemVOList = dishService.getDish(setmealId);
        return Result.success(dishItemVOList);

    }


}
